<template>
  <el-form inline="true" :model="pageForm" label-width="auto">
    <el-form-item label="姓名">
      <el-input v-model="pageForm.name" placeholder="请输入姓名" />
    </el-form-item>
    <el-form-item label="性别" style="width: 200px">
      <el-select v-model="pageForm.gender" placeholder="请输入性别">
        <el-option label="男" value="1" />
        <el-option label="女" value="2" />
      </el-select>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="selectInfo">查询</el-button>
      <el-button @click="cleanSubmit">重置</el-button>
    </el-form-item>
  </el-form>


  <el-table :data="tableData" style="width: 100%">
    <el-table-column prop="id" label="Date" width="180" />
    <el-table-column prop="name" label="Name" width="180" />
    <el-table-column prop="gender" label="Address">
      <template #default="scope">
        {{ scope.row.gender == '1' ? '男' : '女' }}
      </template>
    </el-table-column>
  </el-table>

  <el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :page-sizes="[3, 6, 9, 12]"
    size="default" background="true" layout="total, sizes, prev, pager, next, jumper" :total="total"
    @size-change="handleSizeChange" @current-change="handleCurrentChange" />
</template>

<script setup lang="ts">
import { pageApi } from "@/api/page"
import { onMounted, ref } from "vue"

let pageForm = ref({
  name: '',
  gender: ''
})
const total = ref(0)

const tableData = ref([])

const currentPage = ref(1)
const pageSize = ref(3)
const selectInfo = async () => {
  let result = await pageApi(currentPage.value, pageSize.value, pageForm.value.name, pageForm.value.gender)
  if (result.data) {
    tableData.value = result.data.rows
    total.value = result.data.total
  }
}

const handleSizeChange = (val) => {
  pageSize.value = val
  currentPage.value = 1
  selectInfo()
}
const handleCurrentChange = (val) => {
  currentPage.value = val
  selectInfo()
}

const cleanSubmit = () => {
  pageForm.value = {
    name: '',
    gender: ''
  }
  selectInfo()
}

onMounted(() => {
  selectInfo()
})
</script>

<style scoped></style>
